package com.ymatou.iapi.withdraw.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.withdraw.parameter.ExportWithDrawInvoiceBean;
import com.ymatou.iapi.withdraw.parameter.InputWithDrawResultBean;
import com.ymatou.iapi.withdraw.parameter.PassApprovalBean;
import com.ymatou.iapi.withdraw.parameter.WithDrawResult;
import com.ymatou.iapi.withdraw.parameter.applyBankWithDrawForSellerBean;
import com.ymatou.iapi.withdraw.service.ExportWithDrawInvoiceCall;
import com.ymatou.iapi.withdraw.service.InputWithDrawResultCall;
import com.ymatou.iapi.withdraw.service.PassApprovalCall;
import com.ymatou.iapi.withdraw.service.applyBankWithDrawForSellerCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.database.model.withdraw.Ymt_WithDrawIdempotent;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoiceEx;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoiceExExample;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoiceExample;
import com.ymttest.database.sqlwapper.WithdrawWapper;
import com.ymttest.utils.TestDataManager;
/**
*打款状态导入-买家/买手提现单线下打款
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_InputWithDrawResult{
	private static InputWithDrawResultBean bean;
	private static InputWithDrawResultCall call;
	
	Ymt_WithDrawInvoiceExExample ymtinvoiveEX=new Ymt_WithDrawInvoiceExExample();//提现申请信息主表
	WithdrawWapper WithdrawWapper=new WithdrawWapper();
	
	private final int sellerid=3383;
	private final String sellerName="wesper";
	
	private final int userId=4085;
	private final String userName="lunchzhao";

	private final String fundAccountId_sellerId="925CF663-FCBA-4380-846B-32162E58C345";
	private final String fundAccountName_sellerId="吴文";
	private final String fundAccountNo_sellerId="123456789123";
	
	private final String fundAccountId_buer="925CF663-FCBA-4380-846B-32162E58C317";
	private final String fundAccountName_buer="吴文买家";
	private final String fundAccountNo_buer="987654321789";
	
	private final String abroadFundAccountId="a0d8378e-af28-45bc-b211-5304d4869829";
	private final String abroadFundAccountName="wuwen";
	private final String abroadFundAccountNo="123456789123456";
	
	private final String alipayAccountNo_seller="18621614678";
	private final String alipayAccountName_seller="wuwenseller";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("打款状态导入-买家/买手提现单线下打款");
	}

	@Before
	public void caseUp() {
		bean=new InputWithDrawResultBean();
		call=new InputWithDrawResultCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	/**
	 * 买手申请到银行卡
	 * @param userId 买家/买手
	 * @throws Exception
	 */
	private  String applyBankForseller() throws Exception {
		
		applyBankWithDrawForSellerBean sellerBean=new applyBankWithDrawForSellerBean();
		applyBankWithDrawForSellerCall sellerCall=new applyBankWithDrawForSellerCall();
		WithdrawWapper WithdrawWapper=new WithdrawWapper();
		
		//给帐号充值
		String accountid = AccountCallServiceV2.getAccountId(sellerid, 1);
		AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999999),
				new BigDecimal(0));
		//冻结资金
		BigDecimal freeze= WithdrawWapper.getSumFreezebyUserId(sellerid);
		Logger.comment("################冻结资金："+freeze);
		//查看账户余额
		BigDecimal balance=AccountCallServiceV2.getAccountBalance(sellerid, 1);
		Logger.comment("################账户余额："+balance);
		
		sellerBean.setUserId(sellerid);
		sellerBean.setWithDrawChannel(1);
		sellerBean.setAccountTypeId(1);//提现帐户类型Id，默认值:1.人民币余额帐户
	    sellerBean.setWithDrawAmount(new BigDecimal(1000));
	    sellerBean.setBusinessNo(new TestDataManager().getRandomNum(8));
        sellerBean.setRemark("测试提现到国际银行卡");
        sellerBean.setApplyUserId(sellerid);
        sellerBean.setApplyLoginId(sellerName);
        
        sellerBean.setBankAccountName(abroadFundAccountName);
        sellerBean.setBankAccountNo(abroadFundAccountNo);
        sellerBean.setFundAccountId(abroadFundAccountId);
	    sellerBean.setCurrencyType(1);//4 美元 	 1 人名币
        sellerBean.setIdempotentNo(new TestDataManager().getRandomNum(8));
        
        sellerCall.setData(sellerBean);
        sellerCall.callService();	
		return sellerCall.getInvoiceId();

	}
	
	
	private String setExportWithDeawInvoice_seller() throws Exception {
		
		ExportWithDrawInvoiceBean ebean=new  ExportWithDrawInvoiceBean();
		ExportWithDrawInvoiceCall ecall=new ExportWithDrawInvoiceCall();
		PassApprovalBean bean=new PassApprovalBean();
		PassApprovalCall call=new PassApprovalCall();
		
		String invoiceId=applyBankForseller();
		
		//一级审核
		bean.setInvoiceId(invoiceId);
		bean.setApprovalLevel(1);
		bean.setApprovalResult("一级审核通过_"+TestDataManager.getRandomIntNum(5));
		bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
		bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
		call.setData(bean);
		call.callService();	
		//二级审核
		bean.setApprovalLevel(2);
		bean.setApprovalResult("二级审核通过_"+TestDataManager.getRandomIntNum(5));
		bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
		bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
		call.setData(bean);
		call.callService();	
		//三级审核
		bean.setApprovalLevel(3);
		bean.setApprovalResult("三级审核通过_"+TestDataManager.getRandomIntNum(5));
		bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
		bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
		call.setData(bean);
		call.callService();	
		
	//	bean.setAccountType(1);
		ebean.setOperator("操作人_"+TestDataManager.getRandomIntNum(5));
		ebean.setOperatorId(TestDataManager.getRandomIntNum(5));
		ecall.setData(ebean);
		ecall.callService();
		ecall.callService();
		
		return invoiceId;

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_InputWithDrawResult_001() {
		Logger.start(true,"正例-打款状态导入-买家/买手提现单线下打款-人民币提现到银行卡");
		try {
			//applyBankForseller();
			String  invoiceId=setExportWithDeawInvoice_seller();
			
			ymtinvoiveEX.createCriteria().andWithDrawInvoiceIdEqualTo(invoiceId);
			Ymt_WithDrawInvoiceEx  ex1=WithdrawWapper.selectYmtWithDrawInvoiceEx(ymtinvoiveEX).get(0);
			
			List<WithDrawResult> inputRmbBankEnitiesList=new ArrayList();
			WithDrawResult withDraw=new WithDrawResult();
			withDraw.setbankAccountName(abroadFundAccountName);
			withDraw.setbankAccountNo(abroadFundAccountNo);
			withDraw.setbankBranchName("美国加州");
			withDraw.setbankHostCity("Mobile");
			withDraw.setbankHostState("Alabama");
			withDraw.setbankName("美国银行");
			withDraw.setbatchCode(ex1.getBatchCode());
			withDraw.setisBackInvoice("0");
			withDraw.setorinRemark("YMT提现");
			withDraw.setpaySuccessedFlag("S");
			withDraw.setpubFlag("2");
			withDraw.setremark("测试导入");
			withDraw.setthirdPaymentId("2019080610064311360257230102203");
			withDraw.setpayTime("2019-08-10 16:01:55");
			withDraw.setwithDrawAmount(new BigDecimal(995));
			withDraw.setwithDrawInvoiceId(invoiceId);
			
			inputRmbBankEnitiesList.add(withDraw);

			bean.setInputRmbBankEnitiesList(inputRmbBankEnitiesList);
			bean.setInputTempType("0");
			bean.setoperatorId(TestDataManager.getRandomIntNum(5));
			bean.setoperatorLoginId("操作者用户名_"+TestDataManager.getRandomIntNum(5));
			
			call.setData(bean);
			call.callService();			
			
	
			ymtinvoiveEX.createCriteria().andWithDrawInvoiceIdEqualTo(bean.getInputRmbBankEnitiesList().get(0).getwithDrawInvoiceId());
			Ymt_WithDrawInvoiceEx   ex2=WithdrawWapper.selectYmtWithDrawInvoiceEx(ymtinvoiveEX).get(0);
			Logger.verifyEquals(true, ex2.getInputResult(), "验证InputResult");
			Logger.verifyEquals("处理成功", ex2.getInputResultInfo(), "验证InputResultInfo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_InputWithDrawResult_002() {
		Logger.start(true,"正例-打款状态导入-买家/买手提现单线下打款-人民币提现到支付宝");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_InputWithDrawResult_003() {
		Logger.start(true,"正例-打款状态导入-买家/买手提现单线下打款-其他");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_InputWithDrawResult_004() {
		Logger.start(true,"正例-打款状态导入-买家/买手提现单线下打款-inputTempType为空-返回异常");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_InputWithDrawResult_005() {
		Logger.start(true,"正例-打款状态导入-买家/买手提现单线下打款-人民币提现状态集合为空-返回异常");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}